/*
 * @LastEditors: yuSeen
 * @LastEditTime: 2021-12-24 20:33:33
 * 天凉好个秋
 */
const { app, BrowserWindow, ipcMain } = require("electron");
const path = require("path");
// const { miniShortcut } = require("../electronFun/shortcutKey.ts");
// import { toggleMini, minimize } from './electronFun/windowControl'
const windowControl = require("../electronFun/windowControl.ts");
const reloader = require("electron-reloader");
const windows = require("../electronFun/windows/loginWindow.ts")
const openUrl = require("../electronFun/openUrl.ts")

reloader(module);
function createWindow() {
  const mainWindow = new BrowserWindow({
    frame: false,
    width: 1021,
    height: 670,
    minWidth: 1021,
    minHeight: 670,
    webPreferences: {
      preload: path.join(__dirname, "preload.ts"),
      nodeIntegration: true,
      contextIsolation: false,
      enableRemoteModule: true,
    },
  });
  return mainWindow;
}

app.whenReady().then(() => {
  const mainWindow = createWindow();
  mainWindow.setHasShadow(true)
  mainWindow.loadURL('http://localhost:1223')
  // win.loadURL(process.env.NODE_ENV === 'dev'
  // ? 'http://localhost:3000'
  // :`file://${path.join(__dirname, '../dist/index.html')}`);
  windows(ipcMain)
  for (const [key, value] of Object.entries(windowControl)) {
    windowControl[key](mainWindow, ipcMain);
  }
  openUrl()
  // miniShortcut();
  app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow();
    }
  });
});

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});
